# include <bits/stdc++.h>
using namespace std;
int minReverseCount(string str1,string str2) {
	int len1=str1.length(),len2=str2.length(),result=0;
	if(len1!=len2||str1[0]!=str2[0]||str1[len1-1]!=str2[len2-1]) {
		return -1;
	}
	for(int i=1; i<len2-1; ++i) {
		if(str2[i]!=str1[i]) {
			if(str2[i-1]!=str2[i]&&str2[i+1]!=str2[i]) {
				str2[i]=(str2[i]=='0'?'1':'0');
				result++;
			} else {
				return -1;
			}
		}
	}
	return result;
}
int main() {
	int n;
	string line1,line2;
	cin>>n;
	getline(cin,line1);
	for(int i=0; i<n; ++i) {
		getline(cin,line1);
		getline(cin,line2);
		cout<<minReverseCount(line1,line2)<<endl;
	}
	return 0;
}
